﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
   
    /// </summary>
    public partial class MainWindow : Window
    {
        private string[] _selectedFiles;
        public MainWindow()
        {
            InitializeComponent();
        }
        bool symflag= false;
        short sym = 0;
        private void ButtonNumHandler(string num,TextBlock textblock)
        {
            textblock.Text = textblock.Text + num;
        }
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            if(symflag)
            {
                ButtonNumHandler("1", Text2);
            }
            else
            {
                ButtonNumHandler("1", Text1);
            }
        }

        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            if (symflag)
            {
                ButtonNumHandler("2", Text2);
            }
            else
            {
                ButtonNumHandler("2", Text1);
            }
        }

        private void Button3_Click(object sender, RoutedEventArgs e)
        {
            if (symflag)
            {
                ButtonNumHandler("3", Text2);
            }
            else
            {
                ButtonNumHandler("3", Text1);
            }
        }

        private void Button4_Click(object sender, RoutedEventArgs e)
        {
            if (symflag)
            {
                ButtonNumHandler("4", Text2);
            }
            else
            {
                ButtonNumHandler("4", Text1);
            }
        }

        private void Button5_Click(object sender, RoutedEventArgs e)
        {
            if (symflag)
            {
                ButtonNumHandler("5", Text2);
            }
            else
            {
                ButtonNumHandler("5", Text1);
            }
        }

        private void Button6_Click(object sender, RoutedEventArgs e)
        {
            if (symflag)
            {
                ButtonNumHandler("6", Text2);
            }
            else
            {
                ButtonNumHandler("6", Text1);
            }
        }

        private void Button7_Click(object sender, RoutedEventArgs e)
        {
            if (symflag)
            {
                ButtonNumHandler("7", Text2);
            }
            else
            {
                ButtonNumHandler("7", Text1);
            }
        }

        private void Button8_Click(object sender, RoutedEventArgs e)
        {
            if (symflag)
            {
                ButtonNumHandler("8", Text2);
            }
            else
            {
                ButtonNumHandler("8", Text1);
            }
        }

        private void Button9_Click(object sender, RoutedEventArgs e)
        {
            if (symflag)
            {
                ButtonNumHandler("9", Text2);
            }
            else
            {
                ButtonNumHandler("9", Text1);
            }
        }

        private void Buttonadd_Click(object sender, RoutedEventArgs e)
        {
            symflag = true;
            LabelSym.Content = "+";
            sym = 1;
        }

        private void Buttonsub_Click(object sender, RoutedEventArgs e)
        {
            symflag = true;
            LabelSym.Content = "-";
            sym = 2;
        }

        private void Buttonplus_Click(object sender, RoutedEventArgs e)
        {
            symflag = true;
            LabelSym.Content = "*";
            sym = 3;
        }

        private void Buttondiv_Click(object sender, RoutedEventArgs e)
        {
            symflag = true;
            LabelSym.Content = "/";
            sym = 4;
        }

        private void Buttonequ_Click(object sender, RoutedEventArgs e)
        {
            if(Text1.Text!=""&& Text2.Text!= "")
            {
                switch(sym)
                {
                    case 1:
                        Text3.Text=(double.Parse(Text1.Text)+ double.Parse(Text2.Text)).ToString();
                        break;
                    case 2:
                        Text3.Text = (double.Parse(Text1.Text) - double.Parse(Text2.Text)).ToString();
                        break;
                    case 3:
                        Text3.Text = (double.Parse(Text1.Text) * double.Parse(Text2.Text)).ToString();
                        break;
                    case 4:
                        Text3.Text = (double.Parse(Text1.Text) / double.Parse(Text2.Text)).ToString();
                        break;
                }
            }
            if (Text1.Text == "" && Text2.Text != "" && Text3.Text != "")
            {
                switch (sym)
                {
                    case 1:
                        Text3.Text = (double.Parse(Text3.Text) + double.Parse(Text2.Text)).ToString();
                        break;
                    case 2:
                        Text3.Text = (double.Parse(Text3.Text) - double.Parse(Text2.Text)).ToString();
                        break;
                    case 3:
                        Text3.Text = (double.Parse(Text3.Text) * double.Parse(Text2.Text)).ToString();
                        break;
                    case 4:
                        Text3.Text = (double.Parse(Text3.Text) / double.Parse(Text2.Text)).ToString();
                        break;
                }
            }
            Text1.Text = "";
            Text2.Text = "";
            symflag = false;
            LabelSym.Content = "";
            sym = 0;
        }

        private void Buttonclean_Click(object sender, RoutedEventArgs e)
        {
            Text1.Text = "";
            Text2.Text = "";
            Text3.Text = "";
            symflag = false;
            LabelSym.Content = "";
        }

        private void Buttondel_Click(object sender, RoutedEventArgs e)
        {
            if(symflag)
            {
                if(Text2.Text!="")
                    Text2.Text = Text2.Text.Substring(0, Text2.Text.Length - 1);
            }
            else
            {
                if (Text1.Text != "")
                    Text1.Text = Text1.Text.Substring(0, Text1.Text.Length - 1);
            }
        }
    }
}
